#include <iostream>
#include <thread>
#include <mutex>
#include <fstream>

class LogFile
{
    std::mutex m_mutex;
    std::mutex m_mutex2;
    std::ofstream f;
public:
    LogFile(){
        f.open("log.text");
    }
    void shared_print(std::string msg,int id)
    {
        std::lock(m_mutex,m_mutex2);
        std::lock_guard<std::mutex> locker(m_mutex);
        std::lock_guard<std::mutex> locker2(m_mutex2);
        std::cout <<"from "<<msg<<":"<<id<<std::endl;
    }

    void shared_print2(std::string msg,int id)
    {
        std::lock_guard<std::mutex> locker(m_mutex);
        std::lock_guard<std::mutex> locker2(m_mutex2);
        std::cout <<"from "<<msg<<":"<<id<<std::endl;
    }
};


void function_3(LogFile &log)
{
    for(int i = 0; i > -100; --i)
    {
        log.shared_print(std::string("fn1:"),i);
    }
}

int main()
{
    LogFile log;
    std::thread t1(function_3,std::ref(log));

    for(int i=0; i < 100; ++i)
        log.shared_print2(std::string("main:"),i);

    t1.join();

    return 0;
}
